<?php
// +----------------------------------------------------------------------
// | YBlog
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.yhustc.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yhustc <yhustc@gmail.com>
// +----------------------------------------------------------------------
// $Id$

/**
 +------------------------------------------------------------------------------
 * YBlog系统相关操作
 +------------------------------------------------------------------------------
 * @author    yhustc <yhustc@gmail.com>
 * @version   $Id$
 +------------------------------------------------------------------------------
 */


class SystemAction extends BaseAction
{
	/**
     +----------------------------------------------------------
     * 修复统计计数
     +----------------------------------------------------------
     * @access public 
     +----------------------------------------------------------
     */
	function repaire()
	{
		$Dao = new Model();
		//修复评论数
		$Dao->execute("UPDATE `".C("DB_PREFIX")."posts` p SET comment_count = ( SELECT COUNT( `comment_ID` ) FROM `".C("DB_PREFIX")."comments` c WHERE c.`comment_post_ID` = p.`ID`)");
		//修复分类计数
		$Dao->execute("UPDATE `".C("DB_PREFIX")."category` c SET count = ( SELECT COUNT( `ID` ) FROM `".C("DB_PREFIX")."posts` p WHERE c.`cid` = p.`post_category` AND p.`post_type`='post')");
		
		//修改计数后,日志分类widget使用的数据还是旧的,因此需要把前台缓存清空一下
		clearBlogCache();

		$this->success("评论计数和分类计数均已修复");
	}

	/**
     +----------------------------------------------------------
     * 清除项目缓存
     +----------------------------------------------------------
     * @access public 
     +----------------------------------------------------------
     */
	function clearcache()
	{
		$path = "后台";
		if($_GET['type'] == '0')
		{
			clearCache(0);
			clearCache(1);
			clearCache(2);
			clearCache(3);
		}
		else
		{
			clearBlogCache();
			$path = "前台";
		}

		$this->success($path."缓存已清空");
	}
}
?>